/**
 * 使用面向对象的语言实现一个计算器控制台程序，要求输入两个数和运算符，得到结果
 *
 * 存在的问题：
 * 没有解耦
 */
import * as readline from "readline";


const rl = readline.createInterface(process.stdin, process.stdout);

let numberA = 0;
let numberB = 0;
let operation = "";
let result = 0;
rl.question("请输入数字A\n", input => {
    numberA = Number(input);

    rl.question("请选择运算符（+、-、*、/）\n", input => {
        operation = input;

        rl.question("请输入数字B\n", input => {
            numberB = Number(input);

            switch (operation){
            case "+":
                result = numberA + numberB;
                break;
            case "-":
                result = numberA - numberB;
                break;
            case "*":
                result = numberA * numberB;
                break;
            case "/":
                if(numberB === 0){
                    console.log("被除数为0");
                    rl.pause();
                    return;
                }
                result = numberA / numberB;
                break;
            }

            console.log("结果是：", result);

            rl.pause();
        });
    });
});

